//
// Created by PC on 2022/11/3.
// 将两个已排序的数组合并一个新的有序的数组
//

#include <iostream>
#include "arrUtil.h"

using namespace std;

void merge(int arr1[], int arr2[], int l1, int l2, int arr3[])
{
    int i1 = 0;
    int i2 = 0;
    int i3 = 0;
    while (i1 < l1 and i2 < l2)
    {
        arr3[i3++] = arr1[i1] < arr2[i2] ? arr1[i1++] : arr2[i2++];
        printf("i1:%d,i2:%d\n", i1, i2);
    }
    printArr(arr3, l1 + l2);
    while (i1 < l1)
        arr3[i3++] = arr1[i1++];
    while (i2 < l2)
        arr3[i3++] = arr2[i2++];
}

int main()
{
    int a1[] = { 0, 2, 3, 8};
    int a2[] = { -1, 4, 5};
    int l1 = 4;
    int l2 = 3;
    int ret[l1 + l2];
    merge(a1, a2, l1, l2, ret);
    printArr(ret, l1 + l2);
}
